<template>
<div>
    <van-tabbar 
    v-model="select" 
    active-color="#F63515" 
    inactive-color="#000"  
    @change="changeTabbar">
    <van-tabbar-item   icon="wap-home-o">首页</van-tabbar-item>
    <van-tabbar-item  icon="point-gift-o">分类</van-tabbar-item>
  <van-tabbar-item v-if="$store.getters.getBadgeCount > 0"  icon="shopping-cart-o" :badge="$store.getters.getBadgeCount"
      >购物车</van-tabbar-item
    >

    <van-tabbar-item v-else icon="shopping-cart-o">购物车</van-tabbar-item>
    
    <van-tabbar-item  icon="user-o">我的</van-tabbar-item>
    </van-tabbar>
</div>
</template>

<script>
export default {
  props: {
    active: {
      type: Number,
      default: 0
    },
  },
  data() {
    return {
      select: 0,
    }
  },
  created() {
    // console.log("aaa");
    this.select = this.active
    // console.log(this.select);
    // console.log(this.active);
  },
  methods: {
    changeTabbar(index) {
      // console.log('index:', index);
      if (index === 0) {
        this.$router.push("/").catch(() => {});
      } else if (index === 1) {
        this.$router.push("/home").catch(() => {});
      } else if (index === 2) {
        this.$router.push("/shopcart").catch(() => {});
      } else if (index === 3) {
        this.$router.push("/user").catch(() => {});
      }
    },
  },
};
</script>